<?php
/**
 * To use OpenSocial skins you should look at GadgetsSkins.class. You can find OpenSocial documentation here [http://code.google.com/apis/opensocial/docs/0.7/reference/gadgets.skins.html Static Class gadgets.skins]. This class provides operations for getting display information about the currently shown skin.
 * 
 * Here I'm going to explain how you could use Skins in the sfOpenSocialPlugin. You can choose to use this class in the view or in the action, but it's more straight forward to use it in the view. So in this example I'm going to use just the view to setup the gadget skin. You can find the complete code under "sfOpenSocialPlugin/modules/application"
 * <code>
 * //view
 * 
 * <script type="text/javascript">
 * function setSkin() { 
 *   <?php echo GadgetsSkins::loadSkin(); ?>
 * }
 * </script>
 * <?php echo JSFunction::addJSTags(GadgetsUtil::registerOnLoadHandler(new JSFunction('setSkin'))); ?>
 * </code>
 * Doing this will generate all the code to import the skin from the container. This code will also include the "<Require feature="skins"/>" in the gadget
 * 
 * @package    gadgets
 * @subpackage feature
 * @author     Daniel Botelho <botelho.daniel@gmail.com>
 */
class GadgetsSkins
{
  private static $DEFAULT_CLASS = 'gadgets.skins';
  /**
   * The color that anchor tags should use.
   *
   * @var string 
   */
  private static $ANCHOR_COLOR = 'gadgets.skins.Property.ANCHOR_COLOR';

  /**
   * The color of the background of the gadget. 
   *
   * @var string
   */
  private static $BG_COLOR = 'gadgets.skins.Property.BG_COLOR';
  /**
   * An image to use in the background of the gadget. 
   *
   * @var string
   */
  private static $BG_IMAGE = 'gadgets.skins.Property.BG_IMAGE';

  private static $BG_REPEAT = 'gadgets.skins.Property.BG_REPEAT';
  /**
   * The color that the main font should use
   *
   * @var string
   */
  private static $FONT_COLOR = 'gadgets.skins.Property.FONT_COLOR';
    
  
  private static function getProperty($property,$appendable=false)
  {
  	$html = "gadgets.skins.getProperty($property)";
  	if(!$appendable)
  	  $html .= ";\n";
  	return $html;
  }
  
  public static function loadSkin()
  {
  	$html = "if (typeof(gadgets.skins) != 'undefined'){\n";
    $html .= 'if ('.GadgetsSkins::getFontColor(true).') document.body.style.color = '.GadgetsSkins::getFontColor(true).";\n";
    $html .= 'if ('.GadgetsSkins::getBackgroundColor(true).') document.body.style.backgroundColor = '.GadgetsSkins::getBackgroundColor(true).";\n";
    $html .= 'if ('.GadgetsSkins::getBackgroundRepeat(true).') document.body.style.backgroundRepeat = '.GadgetsSkins::getBackgroundRepeat(true).";\n";
    $html .= 'if ('.GadgetsSkins::getBackgroundImage(true).') document.body.style.backgroundImage = \'url(\'+'.GadgetsSkins::getBackgroundImage(true)."+ ')';\n";
    $html .= 'if ('.GadgetsSkins::getAnchorColor(true).') {document.write(\'<style type="text/css">\');'."\n";
    $html .= 'document.write(\'a:hover, a:visited {  color: \' + '.GadgetsSkins::getAnchorColor(true).'+ \';}\');'."\n";
    $html .= 'document.write(\'a { color: \' + '.GadgetsSkins::getAnchorColor(true).'+ \'; text-decoration: none;}\');'."\n";
    $html .= 'document.write(\'</style>\');}'."\n";
    return $html."}\n";  	
  }
  
  /**
   * Get the color that anchor tags should use.
   *
   * @param boolean $appendable If it's appendable or not
   * @return string HTML string that will be appended in the view
   */
  public static function getAnchorColor($appendable=false)
  {
  	OSConfig::importFeatureSkins();
  	return GadgetsSkins::getProperty(GadgetsSkins::$ANCHOR_COLOR,$appendable);
  }
  
  /**
   * Get the color of the background of the gadget. 
   *
   * @param boolean $appendable If it's appendable or not
   * @return string HTML string that will be appended in the view
   */
  public static function getBackgroundColor($appendable=false)
  {
  	OSConfig::importFeatureSkins();
  	return GadgetsSkins::getProperty(GadgetsSkins::$BG_COLOR,$appendable);
  }
  
  /**
   * Get an image to use in the background of the gadget. 
   *
   * @param boolean $appendable If it's appendable or not
   * @return string HTML string that will be appended in the view
   */
  public static function getBackgroundImage($appendable=false)
  {
  	OSConfig::importFeatureSkins();
  	return GadgetsSkins::getProperty(GadgetsSkins::$BG_IMAGE,$appendable);
  }
  
  public static function getBackgroundRepeat($appendable=false)
  {
  	OSConfig::importFeatureSkins();
  	return GadgetsSkins::getProperty(GadgetsSkins::$BG_REPEAT,$appendable);
  }
  
  /**
   * Get the color that the main font should use.
   *
   * @param boolean $appendable If it's appendable or not
   * @return string HTML string that will be appended in the view
   */
  public static function getFontColor($appendable=false)
  {
  	OSConfig::importFeatureSkins();
  	return GadgetsSkins::getProperty(GadgetsSkins::$FONT_COLOR,$appendable);
  }
}